<style>
	.uploader {
		position: relative;
	}

	.uploader a {

	}

	.uploader input {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		z-index: 10;
		opacity: 0;
	}
</style>
<div class="uploader">
	<a href="javascript:;" class="btn btn-success btn-block" id="status">点击上传</a>
	<input type="file" id="file" name="file" accept="image/*">
</div>
<script>
	$('#file').on('change', function(e) {
		if (e.target.files.length > 0) {
			var file = e.target.files[0];
			var xhr = new XMLHttpRequest();
			xhr.open('POST', '{:U("admin/index/upload")}', true);
			var fd = new FormData;
			fd.append("file", file);
			xhr.onload = function(e) {
				var data = JSON.parse(xhr.responseText);
				$('.uploader #status').text('点击上传');
				if (data.error) {
					alert(data.error);
					return;
				}
				uploadCallback && uploadCallback(data.url);
			};
			xhr.upload && (xhr.upload.onprogress = function(e) {
				if (e.lengthComputable) {
					$('.uploader #status').text('上传中(' + parseInt((e.loaded / e.total) * 100) + ')%');
				}
			});
			xhr.send(fd);
		}
	});
</script>